package com.dotstone.chipism.util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;

import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
import org.eclipse.paho.client.mqttv3.MqttCallback;
import org.eclipse.paho.client.mqttv3.MqttClient;
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.eclipse.paho.client.mqttv3.MqttPersistenceException;
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
import org.json.JSONArray;
import org.json.JSONObject;

import com.dotstone.chipism.bean.Device;
import com.dotstone.chipism.bean.DeviceVersion;
import com.dotstone.chipism.bean.MySocket;
import com.dotstone.chipism.bean.MySocket.RecDataCallBackListener_Serach;
import com.dotstone.chipism.bean.WlanInfo;
import com.dotstone.chipism.listener.AppVersionListener;
import com.dotstone.chipism.listener.DeviceVersionListener;
import com.dotstone.chipism.listener.OnDeviceStatusListener;
import com.dotstone.chipism.listener.OnExtrusionListener;
import com.dotstone.chipism.listener.UpdateDataListener;

import android.content.Context;
import android.util.Log;

public class SocketManager {
	private static SocketManager socketManager;// 单例

	public static int index = 0;
	public static String user_id;
	public static String token;
	public static boolean recreateSucccess = false;
	private boolean remoteSuccess = false;// 是否远程连接成功
	public static int mPairType;
	public HashMap<String, MySocket> sMap = new HashMap<String, MySocket>();
	public List<WlanInfo> mWifiList = new ArrayList<WlanInfo>();
	public boolean pairing = false;
	public boolean needShow = true;
	private Context mContext;
	private boolean running = false;
	private List<Device> devices = new ArrayList<Device>();
	private MqttClient mqttClient;
	private String publishTopic = "d";
	private SendDataSuccessListener sendDataSuccessListener;
	private UpdateProgressListener updateProgressListener;
	private AppVersionListener appVersionListener;
	private DeviceVersionListener deviceVersionListener;
	private OnDeviceStatusListener onDeviceStatusListener;
	private UpdateDataListener onUpdateDataListener;
	private String deviceId;
	private int code;
	private int cmd;
	private int count;
	private String LOCK_TOPIC = "d/service";
	private OrderListener l;
	public HashMap<String, Integer> mStatusMap = new HashMap<String, Integer>();
	public int appVersion;
	public String downloadUrl;
	private String packageName;
	private String remarks;
	private String version;
	private String size;
	private int v = 0;
	private boolean stopByUser = false;
	private OnExtrusionListener onExtrusionListener;
	private boolean needToCheck = false;
	private boolean stop = false;
	private LinkedList<String> queue_local = new LinkedList<String>();
	private boolean localSuccess = false;
	private String command;
	private byte buffer[] = new byte[11];
	public int hardDeviceversionCode;

	public boolean isNeedToCheck() {
		return needToCheck;
	}

	public void setNeedToCheck(boolean needToCheck) {
		this.needToCheck = needToCheck;
	}

	public OrderListener getL() {
		return l;
	}

	public void setL(OrderListener l) {
		this.l = l;
	}

	public int getAppVersion() {
		return appVersion;
	}

	public void setAppVersion(int appVersion) {
		this.appVersion = appVersion;
	}

	public int getV() {
		return v;
	}

	public void setV(int v) {
		this.v = v;
	}

	public boolean isRemoteSuccess() {
		return remoteSuccess;
	}

	public void setRemoteSuccess(boolean remoteSuccess) {
		this.remoteSuccess = remoteSuccess;
	}

	public static SocketManager getInstance() {
		if (socketManager == null) {
			socketManager = new SocketManager();
		}
		return socketManager;
	}

	public boolean isRunning() {
		return running;
	}

	public void setRunning(boolean running) {
		this.running = running;
	}

	public String getDownloadUrl() {
		return downloadUrl;
	}

	public void setDownloadUrl(String downloadUrl) {
		this.downloadUrl = downloadUrl;
	}

	public void startMQTTClient() {
		// String topicName = "a/disconnect";
		// 用户ID
		try {
			Log.e("mqtt", "启动MQTT连接");
			//mqttClient = new MqttClient("tcp://xintek-iot.com:1883", "a/" + SocketManager.getInstance().user_id,new MemoryPersistence());

			mqttClient = new MqttClient("tcp://test.xintek-iot.com:1883", "a/" + SocketManager.getInstance().user_id,	new MemoryPersistence());

			MqttConnectOptions conOptions = new MqttConnectOptions();
			// conOptions.setConnectionTimeout(10);
			conOptions.setKeepAliveInterval(10);
			conOptions.setWill("ERR/Disconnect", user_id.getBytes(), 1, false);
			conOptions.setConnectionTimeout(2000);
			conOptions.setUserName("gjkj"); // 用户名 高金科技
			conOptions.setPassword("password".toCharArray());
			mqttClient.connect(conOptions);
			mqttClient.setCallback(new MqttCallBack());
			Log.i("mqtt", "MQTT连接成功");
			subScribe();
			remoteSuccess = true;
		} catch (MqttException e) {
			e.printStackTrace();
			Log.i("mqtt", "98mqtt连接失败");

			if (!stopByUser) {

				startMQTTClient();
			}
		}

	}

	public void parseRecDataFromLocal(String data) {
		if (data.length() < 10 || data == null) {
			return;
		}
		JSONObject jo;
		try {
			jo = new JSONObject(data);
			String a = jo.getString("a");
			if (a.equals("20000")) {
				Log.i("mqtt", "a = " + a);
				int msgId = jo.getInt("b");
				String g = jo.getString("g");
				JSONObject jo1 = new JSONObject(g);
				int cmd = jo1.getInt("cmd");
				if (cmd == 110) {
					double temp = jo1.getDouble("temperature");
					double humity = jo1.getDouble("humidity");
//					Log.i("wmy", "远程获取温湿度 " + temp + " " + humity);
					String c = jo.getString("c").replace("10,", "");
					if (sMap.get(c) != null) {
						sMap.get(c).setHumity(humity);
						sMap.get(c).setTemp(temp);
					}
				}
				JSONArray jsonArray = jo1.optJSONArray("data");

				int dataja[] = new int[jsonArray.length()];
				// Log.i("wmy", "check status recall = " + jsonArray.length());
				// Log.i("wmy", "jo1 = " + jo1);
				if (jsonArray != null) {
					for (int i = 0; i < jsonArray.length(); i++) {
						dataja[i] = (Integer) jsonArray.get(i);
					}
					if (dataja.length == 8) {
						if (dataja[(jsonArray.length() - 1)] == 121) {
							// Log.i("wmy", "获取ID为" + msgId + "的设备的状态为开");
							DeviceManager.getInstance().setDeviceState(msgId + "", true);
							CheckStatusUtil.getInstance().changeRec(msgId + "");
						} else if (dataja[(jsonArray.length() - 1)] == 120) {
							// Log.i("wmy", "获取ID为" + msgId + "的设备的状态为关");
							DeviceManager.getInstance().setDeviceState(msgId + "", false);
							CheckStatusUtil.getInstance().changeRec(msgId + "");
						} else if (dataja[(jsonArray.length() - 1)] == 255) {
							// Log.i("wmy", "获取ID为" + msgId + "的设备的状态为开");
							DeviceManager.getInstance().setDeviceState(msgId + "", true);
							CheckStatusUtil.getInstance().changeRec(msgId + "");
						} else if (dataja[(jsonArray.length() - 1)] == 0) {
							// Log.i("wmy", "获取ID为" + msgId + "的设备的状态为关");
							DeviceManager.getInstance().setDeviceState(msgId + "", false);
							CheckStatusUtil.getInstance().changeRec(msgId + "");
						}
					} else if (dataja.length == 11) {
						if (dataja[7] == 255) {
							// Log.i("wmy", "获取ID为" + msgId + "的设备的状态为开");
							if (needToCheck) {
								DeviceManager.getInstance().setDeviceState(msgId + "", true);
								CheckStatusUtil.getInstance().changeRec(msgId + "");
							}
						} else if (dataja[7] == 0) {
							// Log.i("wmy", "获取ID为" + msgId + "的设备的状态为关");
							if (needToCheck) {
								DeviceManager.getInstance().setDeviceState(msgId + "", false);
								CheckStatusUtil.getInstance().changeRec(msgId + "");
							}
						}
					}
				}
			}
		} catch (Exception e) {
			// TODO: handle exception
		}
	}

	public void stopMqtt() {
		new Thread(new Runnable() {

			@Override
			public void run() {
				// TODO Auto-generated method stub
				try {
					stopByUser = true;
					mqttClient.disconnect();
				} catch (MqttException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}).start();
	}

	public class MqttCallBack implements MqttCallback {

		@Override
		public void connectionLost(Throwable arg0) {
			remoteSuccess = false;
			if (!stopByUser) {
				startMQTTClient();
			}
		}

		@Override
		public void deliveryComplete(IMqttDeliveryToken arg0) {
			Log.d("mqtt", "发送  = " + arg0.getMessageId() + "完成");
		}

		@Override
		public void messageArrived(String topic, final MqttMessage message) throws Exception {
			Log.e("mqtt", "接收 = " + topic + ":" + message);
			if (topic.equals("a/" + token)) {
				Log.e("mqtt", topic + " 被挤下线");
				if (onExtrusionListener != null) {
					Log.i("wmy", "调用被挤下线的接口");
					onExtrusionListener.OnExtrusion();
				}
				stopByUser = true;
				mqttClient.disconnect();
			} else {
				if (message.toString().equals("10007")) {

				} else {
					new Thread(new Runnable() {

						@Override
						public void run() {
							// TODO Auto-generated method stub
							parseRecData(message.toString());
						}
					}).start();

				}
			}
		}
	}

	private void parseRecData(String data) {
//		Log.i("mqtt", "310 parseRecData" + data);
		if (data.length() < 10 || data == null) {
			return;
		}
		JSONObject jo;
		// Log.e("mqtt", "收");
		try {
			jo = new JSONObject(data);
			String a = jo.getString("a");
			if (a.equals("30501")) {
				String msg = jo.getString("g");
				l.onShow(msg);
			} else if (a.equals("20001")) {
				String c = jo.getString("c");
				String cs[] = c.split(",");
				String deviceId = cs[1];
				Log.i("mqtt", "将状态改为1");
				mStatusMap.put(deviceId, 1);
			} else if (a.equals("20009")) {
				String c = jo.getString("c");
				String cs[] = c.split(",");
				String deviceId = cs[1];
				Log.i("mqtt", "将状态改为9");
				mStatusMap.put(deviceId, 9);
			} else if (a.equals("20012")) {
				String g = jo.getString("g");
				JSONObject jo1 = new JSONObject(g);
				// Log.i("wmy", "解析到最新版本");
				packageName = jo1.getString("packageName");

				if (!packageName.equals(mContext.getPackageName())) {
					return;
				}
				downloadUrl = jo1.getString("downloadUrl");
				remarks = jo1.getString("remarks");
				version = jo1.optString("version");
				size = jo1.optString("packageSize");
				// Log.i("wmy", "解析到最新版本" + downloadUrl + " " + remarks + " " +
				// version + " " + size);
				if (version != null && !version.equals("")) {
					v = Integer.parseInt(version);
				}
				remarks = remarks.replace("\n", "");
				remarks = remarks.replace("\t", "");
				new Thread(new Runnable() {

					@Override
					public void run() {
						// TODO Auto-generated method stub
						try {
							Thread.sleep(5 * 1000);
							if (v > appVersion) {
								Log.i("wmy", "(appVersionListener==null) = " + (appVersionListener == null));
								if (appVersionListener != null) {
									Log.i("wmy", "调用接口");
									appVersionListener.newVersion(remarks, v, downloadUrl, size);
								}
							}
						} catch (InterruptedException e) {
							// TODO Auto-generated catch blocknumber
							e.printStackTrace();
						}
					}
				}).start();
			} else if (a.equals("20004")) {
				String g = jo.getString("g");
				JSONObject jo1 = new JSONObject(g);
				final String pid = jo1.optString("pid");
				final String version = jo1.optString("version");
				final String downloadUrl = jo1.optString("downloadUrl");
				hardDeviceversionCode = Util.getVersionCode(version);
				new Thread(new Runnable() {

					@Override
					public void run() {
						// TODO Auto-generated method stub
						try {
							Thread.sleep(10 * 1000);
							List<Device> devices = DeviceManager.getInstance().getWlans();
							for (int i = 0; i < devices.size(); i++) {
								if (sMap.get(devices.get(i).getDeviceID()) != null) {
									if (sMap.get(devices.get(i).getDeviceID()).isLocalSuccess()) {
										final String socketVersion = sMap.get(devices.get(i).getDeviceID())
												.getVersion();
										int vcode = Util.getVersionCode(socketVersion);
										if (vcode < hardDeviceversionCode && deviceVersionListener != null
												&& sMap.get(devices.get(i).getDeviceID()).getProductId().equals(pid)) {
											Log.e("wmy", "有需要升级的硬件，调用接口");
											// deviceVersionListener.newVersion(socketVersion,versionCode,
											// version, downloadUrl);
											DeviceVersion dv = new DeviceVersion(socketVersion, vcode,
													hardDeviceversionCode, version, downloadUrl);
											deviceVersionListener.newVersion(dv);
											break;
										}
									}
								}
							}
						} catch (InterruptedException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
					}
				}).start();
			} else if (a.equals("20002")) {

			} else if (a.equals("10003")) {
				if (onUpdateDataListener != null) {
					onUpdateDataListener.onUpdate();
				}
			} else if (a.equals("20000")) {
				int msgId = jo.getInt("b");
				String c = jo.getString("c");
				String g = jo.getString("g");
				JSONObject jo1 = new JSONObject(g);
				int cmd = jo1.getInt("cmd");
				if (cmd == 100) {
					JSONArray jsonArray = jo1.optJSONArray("data");
					int dataja[] = new int[jsonArray.length()];
					if (jsonArray != null) {
						for (int i = 0; i < jsonArray.length(); i++) {
							dataja[i] = (Integer) jsonArray.get(i);
						}
						for (int i = 0; i < dataja.length; i++) {
							buffer[i] = (byte) dataja[i];
						}
						byte[] temp = new byte[5];
						System.arraycopy(buffer, 1, temp, 0, 5);
						String add = Util.bytesToHexString(temp).toUpperCase();
						if (!DeviceManager.getInstance().getDeviceById(msgId + "").getDeviceAddress().equals(add)) {
							return;
						}
						if (dataja.length == 8) {
							if (dataja[(jsonArray.length() - 1)] == 121) {
								Log.i("mqtt", "获取ID为" + msgId + "的灯泡的状态为开");
								DeviceManager.getInstance().setDeviceState(msgId + "", true);
								CheckStatusUtil.getInstance().changeRec(msgId + "");
								if (onDeviceStatusListener != null) {
									onDeviceStatusListener.onStatus(data, 0);
								}
							} else if (dataja[(jsonArray.length() - 1)] == 120) {
								Log.i("mqtt", "获取ID为" + msgId + "的灯泡的状态为关");
								DeviceManager.getInstance().setDeviceState(msgId + "", false);
								CheckStatusUtil.getInstance().changeRec(msgId + "");
								if (onDeviceStatusListener != null) {
									onDeviceStatusListener.onStatus(data, 1);
								}
							} else if (dataja[(jsonArray.length() - 1)] == 255) {
								Log.i("mqtt", "获取ID为" + msgId + "的设备的状态为开");
								DeviceManager.getInstance().setDeviceState(msgId + "", true);
								CheckStatusUtil.getInstance().changeRec(msgId + "");
								if (onDeviceStatusListener != null) {
									onDeviceStatusListener.onStatus(data, 0);
								}
							} else if (dataja[(jsonArray.length() - 1)] == 0) {
								Log.i("mqtt", "获取ID为" + msgId + "的设备的状态为关");
								DeviceManager.getInstance().setDeviceState(msgId + "", false);
								CheckStatusUtil.getInstance().changeRec(msgId + "");
								if (onDeviceStatusListener != null) {
									onDeviceStatusListener.onStatus(data, 1);
								}
							}
						} else if (dataja.length == 11) {
							if (dataja[7] == 255) {

								Log.i("mqtt", "获取ID为" + msgId + "的插座的状态为开");
								if (needToCheck) {
									DeviceManager.getInstance().setDeviceState(msgId + "", true);
									CheckStatusUtil.getInstance().changeRec(msgId + "");
								}
								if (onDeviceStatusListener != null) {
									onDeviceStatusListener.onStatus(data, 0);
								}
							} else if (dataja[7] == 0) {
								Log.i("mqtt", "获取ID为" + msgId + "的插座的状态为关");
								if (needToCheck) {
									DeviceManager.getInstance().setDeviceState(msgId + "", false);
									CheckStatusUtil.getInstance().changeRec(msgId + "");
								}
								if (onDeviceStatusListener != null) {
									onDeviceStatusListener.onStatus(data, 1);
								}
							}
						}
					}
				} else if (cmd == 110) {
					double temp = jo1.getDouble("temperature");
					double humity = jo1.getDouble("humidity");
					String deviceId = c.replace("10,", "");
//					Log.i("mqtt", "495 远程获取" + temp + " " + humity + " " + deviceId);
					if (SocketManager.getInstance().sMap.get(deviceId + "") != null) {
//						Log.i("mqtt", "495 远程获取" + temp + " " + humity + " " + deviceId);
						SocketManager.getInstance().sMap.get(deviceId + "").setTemp(temp);
						SocketManager.getInstance().sMap.get(deviceId + "").setHumity(humity);
					}
				}
			} else {

				String g = jo.getString("g");
				JSONObject jo1 = new JSONObject(g);
				code = jo1.getInt("code");
				cmd = jo1.getInt("cmd");
				if (code == 0) {
					Log.i("mqtt", "发送成功");
				}
			}

		} catch (Exception e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}

	}

	public interface OrderListener {

		public void onShow(String msg);

	}

	public void sendRemoteData(final String mac, final String deviceId, final String content) {
		this.deviceId = deviceId;
		// 发送前 先判断能否发送
		// 如果能够发送 将发送后的设备ID变为false
		// 如果不能够发送 则return
		new Thread(new Runnable() {

			@Override
			public void run() {
				// TODO Auto-generated method stub
				if (mqttClient != null && mqttClient.isConnected()) {
					MqttMessage msg = new MqttMessage();
					if (msg != null && content != null) {
						msg.setPayload(content.getBytes());
					} else {
						Log.i("mqtt", msg + " 1 " + content);
						return;
					}
					try {
						Log.i("mqtt", mac + " 发送数据" + publishTopic + "/" + deviceId + " " + content);
						mqttClient.publish(publishTopic + "/" + deviceId, msg);
					} catch (MqttPersistenceException e) {
						e.printStackTrace();
					} catch (MqttException e) {
						e.printStackTrace();
					}
				}
			}
		}).start();
	}

	public void sendRemoteData(final String deviceId, final String content) {
		this.deviceId = deviceId;
		new Thread(new Runnable() {

			@Override
			public void run() {
				// TODO Auto-generated method stub
				if (mqttClient != null && mqttClient.isConnected()) {
					MqttMessage msg = new MqttMessage();
					if (msg != null && content != null) {
						msg.setPayload(content.getBytes());
					} else {
						Log.i("mqtt", msg + " 1 " + content);
						return;
					}
					try {
						Log.i("mqtt", " 发送数据" + publishTopic + "/" + deviceId + " " + content);
						mqttClient.publish(publishTopic + "/" + deviceId, msg);
					} catch (MqttPersistenceException e) {
						e.printStackTrace();
					} catch (MqttException e) {
						e.printStackTrace();
					}
				}
			}
		}).start();
	}

	public void uploadLockRecord(final String cmd) {
		new Thread(new Runnable() {

			@Override
			public void run() {
				// TODO Auto-generated method stub
				if (mqttClient != null && mqttClient.isConnected()) {
					MqttMessage msg = new MqttMessage();
					if (msg != null && cmd != null) {
						msg.setPayload(cmd.getBytes());
					} else {
						Log.i("mqtt", msg + " 1 " + cmd);
						return;
					}
					try {
						Log.i("mqtt", " 发送数据" + LOCK_TOPIC + " " + cmd);
						mqttClient.publish(LOCK_TOPIC, msg);
					} catch (MqttPersistenceException e) {
						e.printStackTrace();
					} catch (MqttException e) {
						e.printStackTrace();
					}
				}
			}
		}).start();
	}

	public void subScribe() {
		if (mqttClient == null) {
			return;
		}
		try {
			mqttClient.subscribe("a/" + user_id);
			if (token != null) {
				if (!token.equals("")) {
					mqttClient.subscribe("a/" + token);
				}
			}else{
				token = (String) SPUtils.get(mContext, "token", "");
				mqttClient.subscribe("a/" + token);
			}
			Log.i("wmy", "user_id = " + user_id);
			mqttClient.subscribe("a/android");
			// mqttClient.subscribe("a/a/version");
			mqttClient.subscribe("a/version/a");
			mqttClient.subscribe("a/all");
		} catch (MqttException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public void initSocket(final Context mContext) {
		this.mContext = mContext;
		if (!running) {
			running = true;
			count = 0;
		} else {
			return;
		}
		new Thread(new Runnable() {

			@Override
			public void run() {
				// TODO Auto-generated method stub
				while (running) {

					try {
						if (count < 10) {
							count++;

							devices = DeviceManager.getInstance().getAllDevice();
							for (int i = 0; i < devices.size(); i++) {
								if (sMap.get(devices.get(i).getDeviceID()) == null
										&& devices.get(i).getDeviceType() == 16) {
									WlanInfo wlanInfo = new WlanInfo("DotStone", "10000000",
											devices.get(i).getDeviceAddress(), devices.get(i).getDeviceID(),
											devices.get(i).getStatus());
									MySocket mySocket = new MySocket(wlanInfo, mContext);
									if (sMap.get(devices.get(i).getDeviceID()) == null) {
										sMap.put(devices.get(i).getDeviceID(), mySocket);
										Log.i("wmy", "将socket放入smap" + devices.get(i).getDeviceID() + " "
												+ mySocket.getId() + " " + mySocket.getMac());
										sMap.get(devices.get(i).getDeviceID()).setRecDataCallBackListener_Serach(
												new RecDataCallBackListener_Serach() {

													@Override
													public void onReceiveData(String data) {
														// TODO Auto-generated
														// method stub
														// Log.i("wmy", "data =
														// " + data);
														if (needToCheck) {
															parseRecData(data);
															// parseRecDataFromLocal(data);
														}
													}
												});
									}
								}
								if (mStatusMap.get(devices.get(i).getDeviceID()) == null
										&& devices.get(i).getDeviceType() == 16) {
									Log.i("wmy", "传入" + devices.get(i).getDeviceID() + devices.get(i).getStatus());
									mStatusMap.put(devices.get(i).getDeviceID(), devices.get(i).getStatus());
								}
							}
						} else {
							running = false;
						}
						Thread.sleep(1000);
					} catch (InterruptedException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			}
		}).start();

	}

	public void setListener() {
		for (int i = 0; i < devices.size(); i++) {
			if (sMap.get(devices.get(i).getDeviceID()) != null) {
				sMap.get(devices.get(i).getDeviceID())
						.setRecDataCallBackListener_Serach(new RecDataCallBackListener_Serach() {

							@Override
							public void onReceiveData(String data) {
								// TODO Auto-generated
								// method stub
								// Log.i("wmy", "data =
								// " + data);
								if (needToCheck) {
									parseRecData(data);
									// parseRecDataFromLocal(data);
								}
							}
						});
			}
		}
	}

	public void clearSocket() {
		sMap.clear();
	}

	public void initRemoteConnect(Context c) {
		this.mContext = c;
		stopByUser = false;
		startMQTTClient();
	}

	public interface SendDataSuccessListener {
		public void onSendDataSuccess(String deviceId);
	}

	public interface UpdateProgressListener {
		public void onUpdateProgress(int status, int progress);
	}

	public void setOnSendDataSuccessListener(SendDataSuccessListener sendDataSuccessListener) {
		this.sendDataSuccessListener = sendDataSuccessListener;
	}

	public void setOnUpdateProgressListener(UpdateProgressListener updateProgressListener) {
		this.updateProgressListener = updateProgressListener;
	}

	public void setAppVersionListener(AppVersionListener appVersionListener) {
		this.appVersionListener = appVersionListener;
	}

	public void setDeviceVersionListener(DeviceVersionListener deviceVersionListener) {
		this.deviceVersionListener = deviceVersionListener;
	}

	public void setOnExtrusionListener(OnExtrusionListener onExtrusionListener) {
		this.onExtrusionListener = onExtrusionListener;
	}

	public void setOnDeviceStatusListener(OnDeviceStatusListener onDeviceStatusListener) {
		this.onDeviceStatusListener = onDeviceStatusListener;
	}

	public void setOnUpdateDataListener(UpdateDataListener onUpdateDataListener) {
		this.onUpdateDataListener = onUpdateDataListener;
	}

}
